package com.lz.yz.member.controller;

import com.github.pagehelper.PageHelper;
import com.lz.yz.base.entity.ReturnValue;
import com.lz.yz.member.entity.Feedback;
import com.lz.yz.member.service.FeedbackService;
import com.util.common.Page;
import com.util.common.QueryList;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
* Created by CodeGenerator on 2017/12/14.
*/
@RestController
@RequestMapping("/feedback")
public class FeedbackController {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Resource
    private FeedbackService feedbackService;

    @Autowired
    HttpServletRequest request;


    @ApiOperation(value="查询意见反馈列表")
    @ApiImplicitParams({
    })
    @GetMapping("/queryFeedbackList")
    public ReturnValue list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize) {

        try {
            PageHelper.startPage(page, pageSize);
            List<Feedback> list = feedbackService.findAll();
            QueryList<Feedback> queryList = new QueryList(list, Page.toPage(list));
            return ReturnValue.generateTrueReturnValue(queryList);
        } catch (Exception e) {
            logger.error("查询意见反馈列表出错" +  e);
            return ReturnValue.generateFalseReturnValue("查询意见反馈列表出错");
        }
    }


    @ApiOperation(value="查询意见反馈详情")
    @GetMapping("/queryFeedback/{id}")
    public ReturnValue details(@PathVariable Integer id) {
        try {
            Feedback feedback=new Feedback();
            feedback=feedbackService.findById(id);
            return ReturnValue.generateTrueReturnValue(feedback);
        } catch (Exception e) {
            logger.error("查询意见反馈详情出错" +  e);
            return ReturnValue.generateFalseReturnValue("查询意见反馈详情出错");
        }
    }


}
